package com.wwwarehouse.contract.contract.info;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.MotionEvent;
import android.view.View;

import com.alibaba.fastjson.JSON;
import com.wwwarehouse.common.tools.rsa.StringUtils;
import com.wwwarehouse.contract.bean.InfoCardContractGoodsDetailBean;
import com.wwwarehouse.contract.bean.InfoCardOrderDetailBean;
import com.wwwarehouse.contract.core.BaseViewPagerFragment;
import com.wwwarehouse.contract.core.ContractConstant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import contract.wwwarehouse.com.contract.R;

/**
 * Created by feng.gao on 2017/11/3.
 * 信息卡 商品明细
 */

public class InfoCardOrderDetailViewPagerFragment extends BaseViewPagerFragment {
	private String mContractUkid;

	@Override
	public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		mConfirmBtn.setVisibility(View.INVISIBLE);
		mCustomScroll.setOnTouchListener(new View.OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				return true;
			}
		});
	}

	@Override
	public void onResponse(String response, int what) {
		if (what == 1) {
			InfoCardContractGoodsDetailBean bean = JSON.parseObject(response, InfoCardContractGoodsDetailBean.class);
			if (bean == null || bean.getList() == null || bean.getList().size() == 0) {
				mStateLayout.showEmptyView(true);
				mStateLayout.setEmptyListener(new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						requestDatas();
					}
				});
				return;
			}
			setData(bean , bean.getList().size() , 7 , InfoCardOrderDetailFragment.class.getName());
		}
	}

	@Override
	public void setTitle() {
		mActivity.setTitle(R.string.contract_modify_info_card_goods_details_title);
	}

	@Override
	public void requestDatas() {
		if (getArguments() == null || StringUtils.isNullString(getArguments().getString(ContractConstant.KEY_MODIFY_PAYMENT_ITEM_CONTRACT_UKID))) {
			mStateLayout.showEmptyView(true);
			mStateLayout.setEmptyListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					requestDatas();
				}
			});
			return;
		}
		mContractUkid = getArguments().getString(ContractConstant.KEY_MODIFY_PAYMENT_ITEM_CONTRACT_UKID);
//		有参数直接请求网络
		Map<String, Object> paramsMap = new HashMap<>();
		paramsMap.put("contractUkid", mContractUkid);
		paramsMap.put("page", 1);
		paramsMap.put("size", 7);
		sendRequest(ContractConstant.METHOD_ORDER_DETAILS_LIST ,paramsMap , 1 );
	}
}
